package view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import view.*;
import control.LoginControl;

public class Login extends JFrame {
	
	
	private JPanel contentPane;
	private JTextField txt_username;
	private JLabel lblPassword;
	private JTextField txt_pass;
	private LoginControl loginControl;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setResizable(false);
		setTitle("Login");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		SpringLayout sl_contentPane = new SpringLayout();
		contentPane.setLayout(sl_contentPane);

		txt_username = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_username, 32,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_username, 128,
				SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, txt_username, 59,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_username, -48,
				SpringLayout.EAST, contentPane);
		contentPane.add(txt_username);
		txt_username.setColumns(10);

		JLabel lblNewLabel = new JLabel("Username");
		sl_contentPane.putConstraint(SpringLayout.WEST, lblNewLabel, 20,
				SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, lblNewLabel, -21,
				SpringLayout.WEST, txt_username);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblNewLabel, 32,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lblNewLabel, -192,
				SpringLayout.SOUTH, contentPane);
		contentPane.add(lblNewLabel);

		lblPassword = new JLabel("Password");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblPassword, 15, SpringLayout.SOUTH, lblNewLabel);
		sl_contentPane.putConstraint(SpringLayout.WEST, lblPassword, 0,
				SpringLayout.WEST, lblNewLabel);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lblPassword, -135, SpringLayout.SOUTH, contentPane);
		lblPassword.setFont(new Font("Tahoma", Font.BOLD, 14));
		contentPane.add(lblPassword);

		txt_pass = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_pass, 25,
				SpringLayout.SOUTH, txt_username);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, txt_pass, -150,
				SpringLayout.SOUTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_pass, 0,
				SpringLayout.WEST, txt_username);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_pass, 0,
				SpringLayout.EAST, txt_username);
		txt_pass.setColumns(10);
		contentPane.add(txt_pass);

		JButton btnLogin = new JButton("Login");
		sl_contentPane.putConstraint(SpringLayout.NORTH, btnLogin, 49, SpringLayout.SOUTH, txt_pass);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, btnLogin, 86, SpringLayout.SOUTH, txt_pass);
		sl_contentPane.putConstraint(SpringLayout.EAST, btnLogin, 276,
				SpringLayout.WEST, contentPane);
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("ss");
				String user= txt_username.getText();
				String pass= txt_pass.getText();
				loginControl= new LoginControl();
				boolean login=loginControl.login(user, pass);
				System.out.println("admin : "+loginControl.getHotel().getEmpOnline());
				F_Main f= new F_Main(loginControl.getHotel().getEmpOnline());
				f.show();
//				
				
				
				
				

			}
		});
		btnLogin.setFont(new Font("Tahoma", Font.PLAIN, 14));
		sl_contentPane.putConstraint(SpringLayout.WEST, btnLogin, 160,
				SpringLayout.WEST, contentPane);
		contentPane.add(btnLogin);
	}
}
